home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / dos6mm.zip / INSTALL.ASM < prev    next >
Assembly Source File  |  1993-03-31  |  14KB  |  298 lines

  1. ;****************************************************************************
  2. ; INSTALL inserts a bookmark in memory that allows TSRs installed above it
  3. ; to be removed from memory. Its syntax is:
  4. ;
  5. ;       INSTALL [bookmark]
  6. ;
  7. ; where "bookmark" is the name of the bookmark. The bookmark name can be
  8. ; passed to REMOVE when a bookmark is removed. Only the first 32 characters
  9. ; of the name are used.
  10. ;****************************************************************************
  11.  
  12. code            segment
  13.                 assume  cs:code
  14.                 org     100h
  15. begin:          jmp     init
  16.  
  17. nextblock       dw      0FFFFh                  ;Pointer to next block
  18. bookmark        db      "(No Name)",24 dup (0Dh);Default bookmark name
  19. signature       db      0,1,2,"INSTALL",2,1,0   ;Program signature
  20. vectors         dw      512 dup (?)             ;Interrupt vectors
  21. prog_id         db      ?                       ;Multiplex ID number
  22. int2Fh          dd      ?                       ;Interrupt 2FH vector
  23.  
  24. ;****************************************************************************
  25. ; MPLEX_INT handles interrupt 2FH. If, on entry, AH is set to INSTALL's
  26. ; multiplex ID number, MPLEX_INT uses the value in AL as a function code.
  27. ; The functions supported are:
  28. ;
  29. ;    00H    Returns FFH in AL to indicate the program is installed
  30. ;           and returns the address of its signature in ES:DI.
  31. ;****************************************************************************
  32.  
  33. mplex_int       proc    far
  34.                 pushf                           ;Save FLAGS register
  35.                 cmp     ah,cs:[prog_id]         ;Branch if AH holds the
  36.                 je      mplex2                  ;multiplex ID
  37.                 popf                            ;Restore FLAGS
  38.                 jmp     cs:[int2Fh]             ;Pass the interrupt on
  39. ;
  40. ; Function 00H verifies that the program is installed.
  41. ;           
  42. mplex2:         popf                            ;Restore FLAGS
  43.                 or      al,al                   ;Branch if function code
  44.                 jnz     mplex3                  ;is other than 00H
  45.                 mov     al,0FFh                 ;Set AL to FFH
  46.                 push    cs                      ;Point ES:DI to the program
  47.                 pop     es                      ;signature
  48.                 mov     di,offset signature
  49. mplex3:         iret                            ;Return from interrupt
  50. mplex_int       endp
  51.  
  52. ;****************************************************************************
  53. ; Data that will be discarded when the program becomes memory-resident.
  54. ;****************************************************************************
  55.  
  56. helpmsg         db      "Places a bookmark in memory that marks TSRs for "
  57.                 db      "unloading.",13,10,13,10
  58.                 db      "INSTALL [bookmark]",13,10,13,10
  59.                 db      "  bookmark  Name of the bookmark being installed."
  60.                 db      13,10,13,10
  61.                 db      "Bookmarks can be removed with INSTALL's companion "
  62.                 db      "program, REMOVE. When a",13,10
  63.                 db      "bookmark is removed, all the TSRs installed after "
  64.                 db      "it are removed, too.",13,10,"$"
  65.  
  66. errmsg1         db      "Requires DOS 3.0 or higher",13,10,"$"
  67. errmsg2         db      "INSTALL cannot be loaded high",13,10,"$"
  68. errmsg3         db      "Program could not be installed",13,10,"$"
  69.  
  70. msg1            db      "INSTALL 1.3 Copyright (c) 1993 Jeff Prosise",13,10
  71.                 db      "From: PC Magazine DOS 6 Memory Management "
  72.                 db      "with Utilities",13,10,13,10
  73.                 db      "Bookmark created. Use REMOVE to remove it."
  74.                 db      13,10,"$"
  75.  
  76. ;****************************************************************************
  77. ; INIT makes the program resident in memory.
  78. ;****************************************************************************
  79.  
  80.                 assume  cs:code,ds:code
  81.  
  82. init            proc    near
  83.                 cld                             ;Clear direction flag
  84.                 mov     si,81h                  ;Point SI to command line
  85.                 call    scanhelp                ;Scan for "/?" switch
  86.                 jnc     checkver                ;Branch if not found
  87.                 mov     ah,09h                  ;Display help text and exit
  88.                 mov     dx,offset helpmsg       ;with ERRORLEVEL=0
  89.                 int     21h
  90.                 mov     ax,4C00h
  91.                 int     21h
  92. ;
  93. ; Check the DOS version and make sure the program isn't loaded high.
  94. ;
  95. checkver:       mov     dx,offset errmsg1       ;Exit if DOS version
  96.                 mov     ah,30h                  ;is less than 3.0
  97.                 int     21h
  98.                 cmp     al,3
  99.                 jae     checkaddr
  100.  
  101. error:          mov     ah,09h                  ;Display error message and
  102.                 int     21h                     ;exit with ERRORLEVEL=1
  103.                 mov     ax,4C01h
  104.                 int     21h
  105.  
  106. checkaddr:      mov     dx,offset errmsg2       ;Error if program is loaded
  107.                 mov     ax,cs                   ;at segment address A000H or
  108.                 cmp     ax,0A000h               ;higher
  109.                 jae     error
  110. ;
  111. ; Parse the command line.
  112. ;
  113.                 call    findchar                ;Advance to first character
  114.                 jc      copy                    ;Branch if no parameters
  115.                 mov     di,offset bookmark      ;Point DI to buffer
  116.                 mov     cx,32                   ;Initialize counter
  117. parse1:         lodsb                           ;Get a character
  118.                 cmp     al,"a"                  ;Capitalize it if it's
  119.                 jb      parse2                  ;between "a" and "z"
  120.                 cmp     al,"z"
  121.                 ja      parse2
  122.                 and     al,0DFh
  123. parse2:         stosb                           ;Store it
  124.                 cmp     al,0Dh                  ;Branch if was a carriage
  125.                 je      copy                    ;return
  126.                 loop    parse1                  ;Loop back for more
  127. ;
  128. ; Copy the interrupt vector table from low memory.
  129. ;
  130. copy:           push    ds                      ;Save DS
  131.                 sub     si,si                   ;Point DS:SI to 0000:0000
  132.                 mov     ds,si
  133.                 assume  ds:nothing
  134.                 mov     di,offset vectors       ;Point DI to storage area
  135.                 mov     cx,512                  ;Initialize counter
  136.                 cli                             ;Disable interrupts
  137.                 rep     movsw                   ;Copy the vector table
  138.                 sti                             ;Enable interrupts
  139.                 pop     ds                      ;Restore DS
  140.                 assume  ds:code
  141. ;
  142. ; Install the program.
  143. ;
  144.                 call    check_install           ;Branch if a copy of INSTALL
  145.                 jnc     install_full            ;is not already installed
  146.  
  147.                 mov     di,offset nextblock     ;Point DI to NEXTBLOCK
  148. install1:       cmp     word ptr es:[di],0FFFFh ;Branch if this is not the
  149.                 jne     install2                ;last block in the chain
  150.                 mov     word ptr es:[di],cs     ;Record the address of this
  151.                 jmp     short install_part      ;block if it is
  152. install2:       mov     es,es:[di]              ;Point ES to next block in
  153.                 jmp     install1                ;the chain and loop back
  154.  
  155. install_full:   call    mplex_id                ;Find a multiplex ID number
  156.                 mov     dx,offset errmsg3       ;Error if none available
  157.                 jc      error
  158.                 mov     prog_id,ah              ;Save the ID number
  159.  
  160.                 mov     ax,352Fh                ;Hook interrupt 2FH
  161.                 int     21h
  162.                 mov     word ptr int2Fh,bx
  163.                 mov     word ptr int2Fh[2],es
  164.                 mov     ax,252Fh
  165.                 mov     dx,offset mplex_int
  166.                 int     21h
  167.  
  168. install_part:   mov     ah,49h                  ;Get the segment address of
  169.                 mov     es,ds:[2Ch]             ;the environment block
  170.                 int     21h                     ;and free the segment
  171.  
  172.                 mov     ah,09h                  ;Display message verifying
  173.                 mov     dx,offset msg1          ;the installation
  174.                 int     21h
  175.  
  176.                 mov     ax,3100h                ;Terminate with function 31H
  177.                 mov     dx,(offset helpmsg - offset code + 15) shr 4
  178.                 int     21h
  179. init            endp
  180.  
  181. ;****************************************************************************
  182. ; FINDCHAR advances SI to the next non-white-space character. On return,
  183. ; carry set indicates EOL was encountered.
  184. ;****************************************************************************
  185.  
  186. findchar        proc    near
  187.                 lodsb                           ;Get the next character
  188.                 cmp     al,09h                  ;Loop if tab
  189.                 je      findchar
  190.                 cmp     al,20h                  ;Loop if space
  191.                 je      findchar
  192.                 cmp     al,2Ch                  ;Loop if comma
  193.                 je      findchar
  194.                 dec     si                      ;Point SI to the character
  195.                 cmp     al,0Dh                  ;Exit with carry set if end
  196.                 je      eol                     ;of line is reached
  197.  
  198.                 clc                             ;Clear carry and exit
  199.                 ret
  200.  
  201. eol:            stc                             ;Set carry and exit
  202.                 ret
  203. findchar        endp
  204.  
  205. ;****************************************************************************
  206. ; SCANHELP scans the command line for a /? switch. If found, carry returns
  207. ; set and SI contains its offset. If not found, carry returns clear.
  208. ;****************************************************************************
  209.  
  210. scanhelp        proc    near
  211.                 push    si                      ;Save SI
  212. scanloop:       lodsb                           ;Get a character
  213.                 cmp     al,0Dh                  ;Exit if end of line
  214.                 je      scan_exit
  215.                 cmp     al,"?"                  ;Loop if not "?"
  216.                 jne     scanloop
  217.                 cmp     byte ptr [si-2],"/"     ;Loop if not "/"
  218.                 jne     scanloop
  219.  
  220.                 add     sp,2                    ;Clear the stack
  221.                 sub     si,2                    ;Adjust SI
  222.                 stc                             ;Set carry and exit
  223.                 ret
  224.  
  225. scan_exit:      pop     si                      ;Restore SI
  226.                 clc                             ;Clear carry and exit
  227.                 ret
  228. scanhelp        endp
  229.  
  230. ;****************************************************************************
  231. ; CHECK_INSTALL returns carry set if the program is already installed,
  232. ; carry clear if it's not. If carry returns set, AH holds the program's
  233. ; multiplex ID number.
  234. ;****************************************************************************
  235.  
  236. check_install   proc    near
  237.                 mov     ax,0C000h               ;Initialize AH and AL
  238.                 mov     cx,40h                  ;Initialize count
  239.  
  240. chinst1:        push    ax                      ;Save AX and CX
  241.                 push    cx
  242.                 sub     di,di                   ;Set ES and DI to 0
  243.                 mov     es,di
  244.                 int     2Fh                     ;Interrupt 2Fh
  245.                 cmp     al,0FFh                 ;Nothing here if AL isn't
  246.                 jne     chinst2                 ;equal to FFH
  247.  
  248.                 mov     si,offset signature     ;See if program signature
  249.                 mov     cx,13                   ;appears at the address
  250.                 repe    cmpsb                   ;returned in ES:DI
  251.                 jne     chinst2                 ;Branch if it does not
  252.  
  253.                 pop     cx                      ;Clear the stack and exit
  254.                 pop     ax                      ;with carry set
  255.                 stc
  256.                 ret
  257.  
  258. chinst2:        pop     cx                      ;Retrieve AX and CX
  259.                 pop     ax
  260.                 inc     ah                      ;Next multiplex ID
  261.                 loop    chinst1                 ;Loop until done
  262.  
  263.                 clc                             ;Exit with carry clear
  264.                 ret
  265. check_install   endp
  266.  
  267. ;****************************************************************************
  268. ; MPLEX_ID searches for an unused multiplex ID number. If one is found,
  269. ; it is returned in AH with carry clear. Carry set means no multiplex
  270. ; ID numbers are currently available.
  271. ;****************************************************************************
  272.  
  273. mplex_id        proc    near
  274.                 mov     ax,0C000h               ;Initialize AH and AL
  275.                 mov     cx,40h                  ;Initialize count
  276.  
  277. mxid1:          push    ax                      ;Save AX and CX
  278.                 push    cx
  279.                 int     2Fh                     ;Interrupt 2Fh
  280.                 or      al,al                   ;Branch if AL=0
  281.                 jz      mxid2
  282.                 pop     cx                      ;Retrieve AX and CX
  283.                 pop     ax
  284.                 inc     ah                      ;Increment ID number
  285.                 loop    mxid1                   ;Loop until done
  286.  
  287.                 stc                             ;Exit with carry set
  288.                 ret
  289.  
  290. mxid2:          pop     cx                      ;Clear the stack and exit
  291.                 pop     ax                      ;with carry clear
  292.                 clc
  293.                 ret
  294. mplex_id        endp
  295.  
  296. code            ends
  297.                 end     begin
  298.